<?php

namespace app\admin\controller;

use app\common\model\PlayBeads as PlayBeadsModel;
/**
 * 念珠控制器
 * Class Pratice
 * @package app\admin\controller
 */
class Playbeads extends Base
{
    /**
     * [index  获取念珠记录]
     * @return json
     * @author [C。]
     */
    public function index()
    {
        $param = input('param.');
        $model = new PlayBeadsModel;
        $this->getPageAndSize($param);
        $map = [];
        $user = $this->user;
        try {
            $count = $model->getCount($map);//满足条件的总数
            $allpage = intval(ceil($count / $this->size));//总页数
            $lists = $model->getList($map, $this->from, $this->size,'p.id,m.img,m.tel,m.username,p.today,p.total,p.insist_day,p.update_time');
            foreach($lists as &$v){
                $http = substr($v['img'],0,4);
                if($http != 'http'){
                    $v['img'] = config('domain_name').$v['img'];
                }
                if(strtotime('today') > strtotime($v['update_time'])){
                    $v['today'] = 0;
                }
            }
        } catch (\Exception $e) {
            return admin_json(-1, '获取失败' . $e->getMessage());
        }
        writelog('查看念珠记录列表',1,$user);
        return admin_json(1, '获取成功', [
            'count' => $count,//总记录数
            'allpage' => $allpage,  //总页数
            'lists' => $lists,  //列表数据
        ]);
    }
}